package bit_operation;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class isUnique {
    public boolean isUnique2(String astr) {
        ExecutorService pool = Executors.newFixedThreadPool(10);
        if(astr.length() > 26) return false;//鸽巢原理
        int[] hash = new int[27];//hash
        for(int i = 0;i <astr.length();i++) {
            if(hash[astr.charAt(i)-'a'] > 0) {
                return false;
            }
            hash[astr.charAt(i)-'a']++;
        }
        return true;
    }
    public boolean isUnique(String astr) {
        if(astr.length() > 26) return false;//鸽巢原理
        int bitMap = 0;
        for(int i = 0;i < astr.length();i++) {//位图
            int x = astr.charAt(i)-'a';
            if(((bitMap >> x) & 1) == 1) {
                return false;
            }
            bitMap = bitMap | 1 << x;
        }
        return true;
    }
}
